﻿#pragma once

#include "../../MirControls/MirControl.h"
#include "../../MirControls/MirAnimatedControl.h"
#include "../../MirControls/MirImageControl.h"
#include "../../../Shared/ServerPackets.h"
#include <string>
#include <vector>

//C# TO C++ CONVERTER NOTE: Forward class declarations:
namespace Client::MirScenes::Dialogs { class ClientTimer; }

namespace S = ServerPackets;
using namespace Client::MirControls;
using namespace Client::MirGraphics;

namespace Client::MirScenes::Dialogs
{
    class TimerDialog final : public MirControl
    {
    private:
        bool _timerStarted = false;
        int _timerCounter = 0;
        long long _timerTime = 0;

        MirAnimatedControl *const _eggTimer = nullptr;
        MirImageControl *const _1000 = nullptr;
        MirImageControl *const _100 = nullptr;
        MirImageControl *const _10 = nullptr;
        MirImageControl *const _1 = nullptr;
        MirImageControl *const _colon = nullptr;
        const int _libraryOffset = 900;

//C# TO C++ CONVERTER WARNING: C++ has no equivalent to a 'readonly' collection which allows modification of internal state:
//ORIGINAL LINE: private readonly List<ClientTimer> ActiveTimers = new List<ClientTimer>();
        std::vector<ClientTimer*> ActiveTimers = std::vector<ClientTimer*>();
        ClientTimer *CurrentTimer = nullptr;

    public:
        virtual ~TimerDialog()
        {
            delete _eggTimer;
            delete _1000;
            delete _100;
            delete _10;
            delete _1;
            delete _colon;
            delete CurrentTimer;
        }

        TimerDialog();

        void Process();

    private:
        ClientTimer *GetBestTimer();

    public:
        ClientTimer *GetTimer(const std::string &key);

        void AddTimer(S::SetTimer *p);

        void ExpireTimer(const std::string &key);

    private:
        void UpdateTimeGraphic();
    };

    class ClientTimer
    {
    public:
        std::string Key;
        unsigned char Type = 0;
        int Seconds = 0;

        long long RelativeTime = 0;
        bool Refresh = false;

        ClientTimer(const std::string &key, int time, unsigned char type);

        void Update(int time, unsigned char type);
    };
}
